{template 'tpl_header'}

<div class="weui-panel weui-panel_access">
    <div class="weui-panel weui-panel_access weui-cell_access" style="margin-bottom:0;">
        <div class="weui-panel__bd">
            <div class="weui-media-box weui-media-box_text">
                <div class="weui-media-box__title">{$insurance_order['name']}</div>
                <div class="weui-media-box__desc insurance-payment_desc">
                    <div class="insurance-payment_info font_color_2">
                        <div class="insurance-payment_title">
                            保障期限：<span style="color: #000;">{php echo date('Y.m.d', $insurance_order['start_day'])} - {php echo date('Y.m.d', $insurance_order['finish_day'])}(共{$day}天)</span>
                        </div>
                        <div class="insurance-payment_price">

                        </div>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
            <div class="weui-media-box weui-media-box_text">
                <a href="{php echo url('entry', array('m' => 'vj_bontrip','do' => 'insurance','op' => 'product','id' => $insurance_order['insurance_id']),true);}" class="weui-cell_link" style="color:#333333;">
                    <div class="weui-media-box__title">保障权益及产品解读</div>
                    <div class="weui-media-box__desc insurance-payment_desc">
                        {if !empty($security) }
                        {loop $security $s}
                        <div class="insurance-payment_info font_color_2">
                            <div class="insurance-payment_title">
                                {$s['security_title']}
                            </div>
                            <div class="insurance-payment_price">
                                {php echo number_format($s['security_price'],2)}元
                            </div>
                            <div class="clear"></div>
                        </div>
                        {/loop}
                        {/if}
                        <div class="insurance-payment_desc__ft">
                        </div>
                    </div>
                </a>
            </div>
        </div>
        <div class="weui-panel__ft">
        </div>
    </div>
</div>

<div class="weui-panel weui-panel_access">
    <div class="weui-cells" style="margin-top: 0;font-size: 14px;">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>被保人</p>
            </div>
            <div class="weui-cell__ft">

            </div>
        </div>
        {if $insurance_order['adult_number'] != 0 }
        {loop $insurance_order['adult_members'] $index $adult_members}
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label2">成年人{php echo $index+1 }</label></div>
            <div class="weui-cell__bd">
                {$adult_members['real_name']} <span style="font-size:12px;color:#bcbcc1;">{if $adult_members['certificate_type'] == 1}护照{else}身份证{/if}：{$adult_members['certificate_no']}</span>
            </div>
            <div class="weui-cell__ft">
            </div>
        </div>
        {/loop}
        {/if}
        {if $insurance_order['child_number'] != 0 }
        {loop $insurance_order['child_members'] $index $child_members}
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label2">未成年人{php echo $index+1 }</label></div>
            <div class="weui-cell__bd">
                {$child_members['real_name']} <span style="font-size:12px;color:#bcbcc1;">{if $child_members['certificate_type'] == 1}护照{else}身份证{/if}：{$child_members['certificate_no']}</span>
            </div>
            <div class="weui-cell__ft">
            </div>
        </div>
        {/loop}
        {/if}
    </div>
</div>

<div class="weui-panel weui-panel_access">
    <div class="weui-cells" style="margin-top: 0;font-size: 14px;">
        <div class="weui-cell">
            <div class="weui-cell__hd font_color_2"><label class="weui-label2">投保人</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" placeholder="请填写投保人" value="{$insurance_order['contact_name']}"
                       disabled>
            </div>
            <div class="weui-cell__ft">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd font_color_2"><label class="weui-label2">手机号码</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="tel" placeholder="请填写手机号" value="{$insurance_order['contact_mobile']}"
                       disabled>
            </div>
            <div class="weui-cell__ft">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd font_color_2"><label class="weui-label2">邮箱</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="email" placeholder="请填写邮箱" value="{$insurance_order['contact_email']}"
                       disabled>
            </div>
            <div class="weui-cell__ft">
            </div>
        </div>
    </div>
</div>
<div class="weui-footer">
    <p class="weui-footer__links">
        <a href="javascript:void(0);" class="weui-footer__link open-popup" data-target="#half">查看详细</a>
    </p>
</div>
<div id="half" class='weui-popup__container popup-bottom'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="toolbar">
            <div class="toolbar-inner" style="background-color: #11a4c0;">
                <div class="pay-title">
                    <p>费用详细</p>
                </div>
                <div class="pay-price"><span class="pay-price_left">共</span><span class="pay-price_right">￥{php echo number_format($insurance_order['total_price'],2)}</span>
                </div>
            </div>
        </div>
        <div class="modal-content">
            <div class="weui-grids" style="padding: 15px .5rem 30px .5rem">
                {if $insurance_order['adult_number'] != 0 }
                <div class="pay-price_content">
                    <div class="pay-price_content_title">
                        成人
                    </div>
                    <div class="pay-price_content_desc">
                        {$insurance_order['adult_number']} x {php echo number_format($insurance_order['adult_price'],2)}
                    </div>
                </div>
                <div class="clear"></div>
                {/if}
                {if $insurance_order['child_number'] != 0 }
                <div class="pay-price_content">
                    <div class="pay-price_content_title">
                        儿童
                    </div>
                    <div class="pay-price_content_desc">
                        {$insurance_order['child_number']} x {php echo number_format($insurance_order['child_price'],2)}
                    </div>
                </div>
                <div class="clear"></div>
                {/if}
            </div>
        </div>
    </div>
</div>

<div class="nav-seize-seat"></div>
<div class="nav-price">
    <div class="nav-price_info">
        <span class="nav-price_info_title">总额：</span><span class="nav-price_info_price">￥{php echo number_format($insurance_order['total_price'],2)}</span>
    </div>
    {if $insurance_order['status'] != 1 }
    <div class="nav-price_button">
        <button type="button" id="payment" class="weui-btn weui-btn_mini weui-btn_primary" style="margin-top: 0">提交订单
        </button>
    </div>
    {/if}
    <div class="clear"></div>
</div>

{template 'tpl_footer'}
<script type="text/javascript" src="{$_W['siteroot']}app/resource/js/lib/mui.min.js"></script>
<script type="text/javascript" src="{$_W['siteroot']}app/resource/js/app/util.js"></script>
<script>
    var is_pay_look = false;
    $(function () {
        FastClick.attach(document.body);
        $('#payment').click(function () {
            if (!is_pay_look) {
                //防止重复提交
                is_pay_look = true;
                var data = {
                    'action': 'get_order_detail',
                    'id': '{$id}',
                    'type' : 'insurance'
                };
                $.ajax({
                    url: "{php echo $this->createMobileUrl('ajax')}",
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == 1) {
                            var data = res.data;
                            util.pay({
                                orderFee : data.total_price,
                                payMethod : 'wechat',
                                orderTitle : data.name,
                                orderTid : data.order_no,
                                module : 'vj_bontrip',
                                type : 'insurance',
                                success : function(result) {
                                $.toast('支付成功');
                                window.location.href = "{php echo $this->createMobileUrl('me'); }";
                                },
                                fail : function(result) {
                                    $.toast(result.message, "cancel");
                                    is_pay_look = false;
                                },
                                complete : function(result) {
                                }
                            });

                        } else {
                            is_pay_look = false;
                            $.toast(res.msg, "cancel");
                        }

                    },
                    error: function (res) {
                        is_pay_look = false;
                        $.toast('请求失败，请检测网络或联系客服', "cancel");
                    }
                });

            }
        });
    });
    $(document).on("open", ".weui-popup-modal", function () {
        console.log("open popup");
    }).on("close", ".weui-popup-modal", function () {
        console.log("close popup");
    });
</script>